<template>
  <el-dialog
    :append-to-body="true"
    @close="closeDialog"
    :visible.sync="dialog"
    :title="is_edit?'编辑工单类型':'添加工单类型'"
    width="420px"
  >
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
      <el-form-item label="工单类型" prop="name">
        <el-input placeholder="输入工单类型" v-model="form.name" style="width: 280px;" maxlength="12" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="loading" size="mini" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { _orderCategoryCreate, _orderCategoryUpdate } from "@/http/ajax";
export default {
  name: "edit",
  props: {
    is_edit: {
      type: Boolean,
      required: true
    },
    cur_this: {
      type: Object,
      required: null
    }
  },
  data() {
    return {
      dialog: false,
      loading: false,
      form: {
        name: ""
      },
      rules: {
        name: [{ required: true, message: "请输入工单类型", trigger: "blur" }]
      }
    };
  },
  created() {},
  methods: {
    doSubmit() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.dialog = true;
          if (this.is_edit) {
            _orderCategoryUpdate(
              this.form,
              res => {
                 this.$message({
                  message: "操作成功",
                  type: "success"
                });
                this.dialog = false;
                this.cur_this.getList();
                this.dataInit();
              },
              err => {}
            );
          } else {
            _orderCategoryCreate(
              this.form,
              res => {
                 this.$message({
                  message: "操作成功",
                  type: "success"
                });
                this.dialog = false;
                this.dataInit();
                this.cur_this.getList();
              },
              err => {}
            );
          }
        }
      });
    },
    dataInit() {
      this.form = {
        name: ""
      };
    },
    closeDialog() {}
  }
};
</script>

<style lang="scss">
</style>
